package pubsub;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import util.ConncetionUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class Sender {
    public static final String EXCHANGENAME="jhj";

    public static void main(String[] args) {
        Connection connection = ConncetionUtil.getConnection();
        Channel channel = null;
        try {
            channel = connection.createChannel();
            channel.exchangeDeclare(EXCHANGENAME,"fanout");
            for (int i = 0; i < 100; i++) {
                channel.basicPublish(EXCHANGENAME,"fanout",null,("发送到交换机上面的数据"+i).getBytes(StandardCharsets.UTF_8));
            }
            //关闭连接
            channel.close();
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
